package cn.dnui_yxk801.dnuifood_16110100801.controller;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import cn.dnui_yxk801.dnuifood_16110100801.Adapter.CollectAdapter;
import cn.dnui_yxk801.dnuifood_16110100801.R;
import cn.dnui_yxk801.dnuifood_16110100801.listener.OnRetrofitListener;
import cn.dnui_yxk801.dnuifood_16110100801.model.UserModel;

import static cn.dnui_yxk801.dnuifood_16110100801.MainActivity.userid;

public class CollectShopFragment extends BaseFragment implements OnRetrofitListener {
//    public View onCreate View(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState){
//
//    }
    private RecyclerView collect_shop_rv;
    private CollectAdapter adapter;
    private UserModel userModel;
    private List collectnull;



    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        setLayout_file(R.layout.collectshopfragment);
        return super.onCreateView(inflater,container,savedInstanceState);
    }

    @Override
    public void onSuccess(Object object, int flag) {
        if (flag==6){
            List collectInfos=(List)object;
            adapter=new CollectAdapter(context,collectInfos);
            collect_shop_rv.setAdapter(adapter);
        }
    }

    @Override
    public void onFalure(String msg) {
        adapter=new CollectAdapter(context,collectnull);
        collect_shop_rv.setAdapter(adapter);
    }

    @Override
    void initViews() {
        collect_shop_rv=view.findViewById(R.id.rv_ctsp);
        collect_shop_rv.setLayoutManager(new LinearLayoutManager(getActivity()));
        collect_shop_rv.setHasFixedSize(true);
    }

    @Override
    void initEvents() {

    }

    @Override
    void initData() {
        userModel=new UserModel();
        userModel.getAllUserCollection(userid,"0",this);
    }

//    @Override
//    void initLayout() {
//        layout_file= R.layout.collectshopfragment;
//        setLayout_file(layout_file);
//    }
}
